<?php
	
	$url = $config->getVar('url');
	$pathScripts = $config->getVar('scripts');
	$pathStyles = $config->getVar('css');
	//ici nous sommes en Ajax, pas de rendu par drupal, il faut donc que l'on s'occupe de tout le HTML
	echo '
	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	<html xmlns="http://www.w3.org/1999/xhtml">
		<head>
			<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
			<title>Ajout d\'un editeur</title>
			<link rel="stylesheet" href="'.$pathStyles.'/modal.css" type="text/css" media="screen" />
			<script type="text/javascript" src="'.$pathScripts.'/jQuery.js"></script>
			<script type="text/javascript" src="'.$pathScripts.'/jQueryModal.js"></script>
			<script type="text/javascript" src="'.$pathScripts.'/jQueryValidate.js"></script>
			<script type="text/javascript" src="'.$pathScripts.'/jQuerySelectBox.js"></script>
			<script type="text/javascript" src="'.$pathScripts.'/ajaxAddObject.js"></script>
		</head>
		<body>
			<center>';
				switch($typeElement)
				{
					case 'publisher' :
						echo '<h2>Ajout d\'un editeur</h2>';
					break;
					case 'serie' :
						echo '<h2>Ajout d\'une s&eacute;rie</h2>';
					break;
					case 'drawer' :
						echo '<h2>Ajout d\'un dessinateur</h2>';
					break;
					case 'scriptWritter' :
						echo '<h2>Ajout d\'un sc&eacute;nariste</h2>';    
					break;
				}
				echo '
				<form method="post" class="formElement" id="formPublisher" action="'.$url.'/ajax.php?action=ajaxAddElement">
					<fieldset>
						<legend>Veuillez remplir le formulaire d\'ajout d\'un &eacute;l&eacute;ment</legend>';
						
						
					if ($typeElement == 'publisher')
					{	
						echo '
						<p class="field">
							<label for="nameElement">Nom de l\'editeur</label>
							<input type="text" name="nameElement" class="required" id="nameElement" /><br />
						</p>
						<input type="hidden" name="submitted" value="true">
						<input type="hidden" name="typeElement" value="publisher">
						<p>
							<input type="submit" value="Enregistrer le nouvel editeur" /><br />
						</p>';
					}
					else if ($typeElement=='drawer')
					{    
						echo '
						<p class="field">
							<label for="nameElement">Nom du dessinateur</label>
							<input type="text" name="nameElement" class="required" id="nameElement" /><br />
						</p>
						<input type="hidden" name="submitted" value="true">
						<input type="hidden" name="typeElement" value="drawer">
						<p>
							<input type="submit" value="Enregistrer le nouveau dessinateur" /><br />
						</p>';
					}
					else if ($typeElement=='scriptWritter')
					{    
						echo '
						<p class="field">
							<label for="nameElement">Nom du sc&eacute;nariste</label>
							<input type="text" name="nameElement" class="required" id="nameElement" /><br />
						</p>
						<input type="hidden" name="submitted" value="true">
						<input type="hidden" name="typeElement" value="scriptWritter">
						<p>
							<input type="submit" value="Enregistrer le nouveau sc&eacute;nariste" /><br />
						</p>';
					}
					else if ($typeElement=='serie')
					{
						echo '
						<p class="field">
							<label for="nameElement">Nom </label>
							<input type="text" name="nameElement" class="required" id="nameElement"  />
						</p>
						<p class="field">
							<label for="genreSerie">Genre </label>
							<input type="text" name="genreSerie" class="required" id="genreSerie"/>
						</p>
						<p class="field">
							<label for="typeSerie">Type </label>
							<input type="text" name="typeSerie" class="required" id="typeSerie"/>
						</p>
						<p class="field">
							<label for="keywordsSerie">Mots cles </label>
							<textarea name="keywordsSerie" id="keywordsSerie"></textarea>
						</p>
						<p class="field">
							<label for="statePublisher">Etat Editeur </label>
							<select type="text" name="statePublisher" id="statePublisher">
								<option value="en_cours" selected="selected">En cours</option>
								<option value="finie">Termin&eacute;e</option>
								<option value="oneshot">OneShot</option>
								<option value="inconnu">Inconnu</option>
							</select>
						</p>
						<p class="field">
							<label for="stateBDBDEC">Etat BDBDEC </label>
							<select type="text" name="stateBDBDEC" id="stateBDBDEC">
								<option value="en_cours" selected="selected">En cours</option>
								<option value="finie">Termin&eacute;e</option>
								<option value="oneshot">OneShot</option>
								<option value="inconnu">Inconnu</option>
							</select>
						</p>
						<input type="hidden" name="submitted" value="true">
						<input type="hidden" name="typeElement" value="serie">
						<p>
							<input type="submit" value="Enregistrer la nouvelle s&eacute;rie" /><br />
						</p>';
					}
			
					echo '
					</fieldset>
				</form>
				<script type="text/javascript">
					//on balance le resultat dans une nyroModal des qu\'il est valide
					 $.validator.setDefaults({
						submitHandler: function() { 
							$(".formElement").nyroModalManual({
								endRemove : callbackElement
							});
							}
					 });

					 //on active le plugin de validation				
					$().ready(function() {
						$("#formPublisher").validate({';
						
					//en fonction de l\'element on change les parametres de verification du formulaire
					switch($typeElement)
					{
						case 'publisher' :
						case 'drawer' :
						case 'scriptWritter' :
							echo '
							rules :{
								nameElement: {required:true, maxlength:64}
							},
							messages: {
								nameElement: {required:"Requis", maxlength:"64 caract&egrave;res max"}
							}';
						break;
						case 'serie' :
							echo '
							rules : {
								nameElement: {required:true, maxlength:64},
								genreSerie: {required:true, maxlength:20},
								typeSerie: {required:true, maxlength:20}
							
							},
							messages: {
								nameElement: {required:"Requis", maxlength:"64 caract&egrave;res max"},
								genreSerie: {required:"Requis", maxlength:"20 caract&egrave;res max"},
								typeSerie: {required:"Requis", maxlength:"20 caract&egrave;res max"}
							}';
						break;
					}
				
							echo '
							});
						 //ca n\'a pas l\'air de marcher...   
						$("input#nameElement").focus();
					});
					
				</script>
				<br />
				<a href="'.$url.'/bdbdec.php?action=addBook" class="nyroModalClose"><small>Retour</small></a>
			</center>
		</body>
	</htm>';
	
?>
